
local ddcl = require "ddcl"
ddcl.init()
ddcl.open_all()

local service = require "ddcl.service"
local inspect = require "ddcl.inspect"
local ws_client = require "ddwebsocket.client"
local ws_server = require "ddwebsocket.server"
local base64 = require "ddmath.base64"


service.start(function()
    local client = ws_client({
        host = "127.0.0.1",
        port = 12001,
        on_message = function(c, data)
            print("message:", data)
        end,
        on_close = function(c)
            print("on_close")
        end,
    })

    local server = ws_server({
        host = "127.0.0.1",
        port = 12000,
        connect_fn = function(s, c)
        end,
        message_fn = function(s, c, data)
            print("s message_fn:", c.fd, data)
            c.send(data, false, true)
            service.sleep(1000)
            c.close()
        end,
        close_fn = function(s, c)
            print("s close_fn:", c.fd)
        end,
    })
    server.listen()

    client.connect()
    print(inspect(client.info))
    client.send("hello")
    client.send("ok")

end)
